<?php
if(!defined('ADMINPX') || !defined('ADMIN')) {
	exit('Access Denied');
}
$act =$_GET['act'];
$id  =$_GET['id'];
$type=$_GET['type'];

if($act=='xgcj'){
   $row=$db->get_one('plugin_caiji',"`id` ='$id'",'');
   $rowt=$db->get_one('forum_class',"`id` ='$row[cid]'",'');
if($row[zdcjsz] == '1'){$zdcjsz='CHECKED';}else{$zdcjsza='CHECKED';}
echo <<<end
<div class="admin">修改帖子采集<br/></div>
<form method="POST" action="$plugin_admindz&pod=index&act=xgcjok&id=$id" >
任务名称 <input  type="text" name="name" value="$row[name]" size=35/><br/>
被采网址 <input  type="text" name="url" value="$row[url]" size=35/><br/>
选择论坛 <select name="cid">
<option value="$row[cid]">$rowt[name]</option>
end;
    $sql=$db->query('forum_class',"1 ORDER BY `id` ",'');
	  while($rowa=mysql_fetch_array($sql)){
      echo "<option value=\"$rowa[id]\">$rowa[name]</option>";
	  }
echo <<<end
</select><br/>
会员 uid  <input  type="text" name="uid" value="$row[uid]" size=35/><br/>
会员昵称 <input  type="text" name="uname" value="$row[uname]" size=35/><br/>
列表规则
<input  type="text" name="p1" value='$row[yycj1]' size=25/>
<input  type="text" name="p2" value='$row[yycj2]' size=1/>
<input  type="text" name="p3" value='$row[yycj3]' size=1/><br/>
填充网址
<input type="text" name="zzurl" value='$row[zzurl]' size=25/>
<input type="text" name="zzurla" value='$row[zzurla]' size=5/><br/>
标题规则
<input type="text" name="px1" value='$row[cccj1]' size=25/>
<input type="text" name="px2" value='$row[cccj2]' size=5/><br/>
内容规则
<input type="text" name="px3" value='$row[cccj3]' size=25/>
<input type="text" name="px4" value='$row[cccj4]' size=5/><br/>
图片规则
<input type="text" name="img_a" value='$row[img_a]' size=25/>
<input type="text" name="img_b" value='$row[img_b]' size=5/><br/>
填充图片
<input type="text" name="img_url" value='$row[img_url]' size=25/>
<input type="text" name="img_urla" value='$row[img_urla]' size=5/><br/>
网页编码
<input type="text" name="bianm" value='$row[bianm]' size=25/><br/>
自动采集
     <input type="radio" $zdcjsz name="zdcjsz" value="1" />开启
     <input type="radio" $zdcjsza name="zdcjsz" value="0" />关闭(每天)
<br/>
采集条数
<input type="text" name="ys" value='$row[ggyid]' size=35/><br/>
<input class="submit" type="submit" value="确定修改" name="b1" />
</form>
end;
}else if($act=='xgcjok'){
    	    if($db->update('plugin_caiji',"`bianm`='$_POST[bianm]',`zzurla`='$_POST[zzurla]',`img_urla`='$_POST[img_urla]',`img_url`='$_POST[img_url]',`zdcjsz`='$_POST[zdcjsz]',`img_a`='$_POST[img_a]',`img_b`='$_POST[img_b]',`zzurl`='$_POST[zzurl]',`url`='$_POST[url]',`cccj1`='$_POST[px1]',`cccj2`='$_POST[px2]',`cccj3`='$_POST[px3]',`cccj4`='$_POST[px4]',`yycj1`='$_POST[p1]',`yycj2`='$_POST[p2]',`yycj3`='$_POST[p3]',`cid`='$_POST[cid]',`uid`='$_POST[uid]',`name`='$_POST[name]',`ggyid`='$_POST[ys]',`name`='$_POST[name]' ","`id`= '$id'")){
	           echo"修改采集成功<br/>";
          }else{
		         echo"修改采集失败<br/>";
          }
     echo "正在自动返回.......<br/><a href=\"$plugin_admindz&pod=index&act=xgcj&id=$id\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=$plugin_admindz&pod=index&act=xgcj&id=$id'>";
}else if($act=='cjtz'){
echo <<<end
<div class="admin">创建采集任务<br/></div>
<form method="POST" action="$plugin_admindz&pod=index&act=cjltok&type=1" >
任务名称 <input  type="text" name="name" value="帖子采集" size=35/><br/>
被采网址 <input  type="text" name="url" value="http://3g.163.com/tech/special/000903FV/tongxinyaowenlist.html" size=35/><br/>
选择论坛 <select  name="cid" />
end;
    $sql=$db->query('forum_class'," ORDER BY `id` ",'');
	  while($rowa=mysql_fetch_array($sql)){
      echo "<option value=\"$rowa[id]\">$rowa[name]</option>";
	  }
echo <<<end
</select><br/>
会员 uid  <input  type="text" name="uid" value="1000" size=35/><br/>
会员昵称 <input  type="text" name="uname" value="admin" size=35/><br/>
列表规则
<input  type="text" name="p1" value='<a href="http://3g.163.com/tech/' size=25/>
<input  type="text" name="p2" value='">' size=1/>
<input  type="text" name="p3" value='</a>' size=1/><br/>
填充网址
<input type="text" name="zzurl" value='http://3g.163.com/tech/' size=35/><br/>
标题规则
<input type="text" name="px1" value='<div class="atitle tCenter">' size=25/>
<input type="text" name="px2" value='</div>' size=5/><br/>
内容规则
<input type="text" name="px3" value='<div class="content">' size=25/>
<input type="text" name="px4" value='</div>' size=5/><br/>
图片规则
<input type="text" name="img_a" value='<img src="' size=25/>
<input type="text" name="img_b" value='">' size=5/><br/>
采集条数
<input type="text" name="ys" value='5' size=35/><br/>
<input class="submit" type="submit" value="确定创建" name="b1" />
</form>
end;
}else if($act=='cjltok'){
           $mmm=user_mm(time());
    	    if($db->insert('plugin_caiji','`id`,`lx`, `cid`, `uid`, `uname`, `mm`, `name`, `url`, `ggyid`, `yycj1`, `yycj2`, `yycj3`, `zzurl`, `cccj1`, `cccj2`, `cccj3`, `cccj4`, `img_a`, `img_b`',"NULL , '$type', '$_POST[cid]' , '$_POST[uid]', '$_POST[uname]', '$mmm', '$_POST[name]', '$_POST[url]', '$_POST[ys]', '$_POST[p1]', '$_POST[p2]', '$_POST[p3]', '$_POST[zzurl]', '$_POST[px1]','$_POST[px2]','$_POST[px3]','$_POST[px4]', '$_POST[img_a]','$_POST[img_b]' ")){
	           echo"创建论坛采集成功<br/>";
          }else{
		         echo"创建论坛采集失败<br/>";
          }
     echo "正在自动返回.......<br/><a href=\"$plugin_admindz&pod=index&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=$plugin_admindz&pod=index&'>";
}else if($act=='scltts'){
	 echo "注意：删除后，不能恢复采集规则！<br/>";
   echo "<a href=\"$plugin_admindz&pod=index&act=sclt&id=$id\">确定删除</a><br/>";
}else if($act=='sclt'){
   $db->delete('plugin_caiji'," `id` = '$id'");
	 echo "删除成功<br/>";
   echo "正在自动返回.......<br/><a href=\"$plugin_admindz&pod=index&\">请手动返回</a><br/><meta http-equiv=refresh content='3;url=$plugin_admindz&pod=index&'>";
}else if($act=='cscj'){
   $row=$db->get_one('plugin_caiji'," `id` ='$id'",'');
   echo $urllkk=$row[url];
   $ccc=Bingz_collection($urllkk);
   if($row[yycj3]){
      $preg  = '@'.$row[yycj1].'(.*?)'.$row[yycj2].'(.*?)'.$row[yycj3].'@is' ;
   }else{
      $preg  = '@'.$row[yycj1].'(.*?)'.$row[yycj2].'@is' ;
   }
   preg_match_all ($preg,$ccc,$zzza);
   echo'<div class="admin">采集数据如下请确认<br/></div> ';
   if(!$ccc){ echo '数据获取失败！';}
   //print_r($zzza);
   $aa='0';
   foreach($zzza[1] as $a=> $lists){
     echo $urlla =$row['zzurl'].$lists.$row['zzurla'];
     $ab=Bingz_collection($urlla);
     preg_match('@'.$row[cccj1].'(.*?)'.$row[cccj2].'@i',$ab,$tit1);
     preg_match('@'.$row[cccj3].'(.*?)'.$row[cccj4].'@s',$ab,$tit2);
     $tit1[1]=iconv($row[bianm],'utf-8',strip_tags($tit1[1]));
     $tit2[1]=iconv($row[bianm],'utf-8',strip_tags($tit2[1]));
     echo "<div class=\"admin_a\">【标题】：".$tit1[1]."<br/></div>";
     echo "<div class=\"admin_a\">【内容】：".$tit2[1]."<br/></div>";
     $aa++;
     if($aa == '3'){ break; }
   }
}else if($act=='cjqr'){
   $row=$db->get_one('plugin_caiji',"`id` ='$id'",''); 
   $urllkk="$row[url]$row[ysbm]";
   $c=Bingz_collection($urllkk);
   if($row[yycj3]){
      $preg  = '@'.$row[yycj1].'(.*?)'.$row[yycj2].'(.*?)'.$row[yycj3].'@is' ;
   }else{
      $preg  = '@'.$row[yycj1].'(.*?)'.$row[yycj2].'@is' ;
   }
   preg_match_all ($preg,$c,$zzza);
   echo'<div class="admin">采集数据如下请确认<br/></div> ';
   if(!$c){ echo '数据获取失败！';}
   $asa='0';
   $bsb='1';
   foreach($zzza[1] as $a=> $lists){
    $urlla =$row['zzurl'].$lists.$row['zzurla'];
    $ab=Bingz_collection($urlla);
    preg_match('@'.$row[cccj1].'(.*?)'.$row[cccj2].'@i',$ab,$tit1);
    preg_match('@'.$row[cccj3].'(.*?)'.$row[cccj4].'@s',$ab,$tit2);
    $tit2[1]=str_replace('</p>','
    ',$tit2[1]);
          if(!$row[cccj3]){$tit2[1]=$tit1[1];}
      	 	$time=time();
      	 	$tit1[1]=iconv($row[bianm],'utf-8',strip_tags($tit1[1]));
      	 	echo"<div class=\"admin_a\">标题：$tit1[1]<br/></div>";
      	 	if($tit1[1] && $tit2[1]){
      	    if($row[lx] == 1){
      	     if($bb=$db->get_one('forum_class'," `id` ='$row[cid]' ",'')){
      	       if(!$bbssa=$db->get_one('forum'," `cid` ='$row[cid]' AND `name` ='$tit1[1]'",'')){
                 ###########
                 $name='';
                 $fmpuid='';
                 if(!$row[cccj3]){
                 	if(preg_match('@'.$row[img_a].'(.*?)'.$row[img_b].'@',$ab,$name)){
                    if($fmpuid=Bingz_forum_upload_post($row[uid],$row[img_url].$name[1].$row[img_urla])){
               	     	 $tit2[1]='[attach]'.$fmpuid.'[/attach]///'.$tit2[1];
               	    }
                  }
                 }else{
                 	if(preg_match('@'.$row[img_a].'(.*?)'.$row[img_b].'@',$tit2[1],$name)){
                    if($fmpuid=Bingz_forum_upload_post($row[uid],$row[img_url].$name[1].$row[img_urla])){
               	     	 $tit2[1]=str_replace($name[0],'[attach]'.$fmpuid.'[/attach]',$tit2[1]);
               	    }
                  }
                 }
                 ###########
                 $tit2[1]=iconv($row[bianm],'utf-8',strip_tags($tit2[1]));
                 Bingz_forum_post($row[cid],$row[uid],$tit1[1],$tit2[1]);
                 $asa++;
               }
             }
      	    }
      	  }
          $bsb++;
          if($bsb > $row[ggyid]){ break; }
   }
   echo "<div class=\"admin_b\"> 成功: $asa / 总采集: $row[ggyid] </div>";
}else{
      echo"<a href=\"$plugin_admindz&pod=index&act=cjtz\">创建采集任务</a><br/>";
      echo'<div class="admin">帖子采集任务<br/></div>';
      $sql_li=$db->query('plugin_caiji',"`lx` ='1' ORDER BY `id`",'');
      $l_s='1';
	    while($row=mysql_fetch_array($sql_li)){
echo <<<end
<div class="admin_a">$l_s 、$row[name]
<a href="$plugin_admindz&pod=index&act=xgcj&id=$row[id]">编辑</a>
<a href="$plugin_admindz&pod=index&act=cscj&id=$row[id]">测试</a>
<a href="$plugin_admindz&pod=index&act=cjqr&id=$row[id]">采集</a>
<a href="$plugin_admindz&pod=index&act=scltts&id=$row[id]">删除</a>
</div>
end;
		  $l_s++;
	  }
}
echo"<div class=\"admin_a\"><a href=\"$plugin_admindz&pod=index&\">返回采集任务</a></div>";
?>